package com.fanrenqiji.entity;

import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.List;

/**
 * Created by yanwt on 2017/1/3.
 * 课程信息 设置课程基本信息，年级，主讲老师
 */
@Getter
@Setter
@Entity
@Table(name = "tb_course")
@org.hibernate.annotations.Table(appliesTo = "tb_course",comment = "课程信息")
@org.hibernate.annotations.DynamicInsert
@org.hibernate.annotations.DynamicUpdate
@org.hibernate.annotations.Cache(region="course", usage = CacheConcurrencyStrategy.READ_WRITE)
public class CourseEntity extends DataEntity {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;
    @Column(columnDefinition=("varchar(200) default null comment '课程名称'"))
    private String title;
    @Column(columnDefinition=("varchar(200) default null comment '课程封面'"))
    private String cover;


    @Column(name="score",columnDefinition=("decimal(19,2) default null comment '课程评分'"))
    private BigDecimal score;

    @Column(name="total_seconds",columnDefinition=("int(11) default null comment '总时长'"))
    private int totalSeconds;
    @Column(name="abstract_content",columnDefinition="text not null comment '课程简介'")
    private String abstractContent;
    @Column(name="outline",columnDefinition=("text default null comment '课程大纲'"))
    private String outline;
    @Column(columnDefinition=("text default null comment '课程介绍'"))
    private String introduction;
    @ManyToOne
    @JoinColumn(name="teacher_id",columnDefinition=("bigint(20) default null comment '主讲老师ID'"))//,foreignKey = @ForeignKey(value=ConstraintMode.NO_CONSTRAINT))
    @Where(clause="del_flag="+DEL_FLAG_NORMAL)
    private TeacherEntity teacher;
    @Column(name="original_price",columnDefinition=("decimal(19,2) default null comment '课程原价'"))
    private BigDecimal originalPrice;   //原价
    @Column(name="present_price",columnDefinition=("decimal(19,2) default null comment '课程现价'"))
    private BigDecimal presentPrice;    //现价
    @Column(name="buy_count",columnDefinition=("int(11) default null comment '购买人数'"))
    private int buyCount;         //购买人数
    @Column(name="view_count",columnDefinition=("int(11) default null comment '观看人数'"))
    private int viewCount;         //观看人数
    @Column(columnDefinition=("int(1) default null comment '是否免费'"))
    private int free;           //是否免费
    @Column(columnDefinition=("int(11) default null comment '课程序号'"))
    private int seq;

    @ManyToMany
    @JoinTable(name = "tb_course_event_case", joinColumns = {@JoinColumn(name = "course_id",columnDefinition=("bigint(20) not null comment '课程ID'"))}, inverseJoinColumns = {@JoinColumn(name = "event_case_id",columnDefinition=("bigint(20) not null comment '事件实例ID'"))})//,foreignKey = @ForeignKey(value=ConstraintMode.NO_CONSTRAINT),inverseForeignKey=@ForeignKey(value=ConstraintMode.NO_CONSTRAINT))
    @Where(clause="del_flag="+DEL_FLAG_NORMAL)
    private List<EventCaseEntity> eventCases;

}
